<template>
  <div>
      <el-row>
          <el-col :span="24" align="right">
              <div style="margin-top:10px">
                <el-input style="width:200px" v-model="filters.name" placeholder="请输入事件名称"></el-input>
                <el-select v-model="filters.kind" placeholder="请选择事件类型">
                  <el-option :value="1" label="一般事件"></el-option>
                  <el-option :value="2" label="重大事件"></el-option>
                </el-select>
                <!-- <el-select v-model="filters.status" placeholder="请输入事件处理状态">
                  <el-option v-for="(v,i) of EventStatus" :key="i" :label="v.sseventStatusTypeName" :value="v.sseventStatusTypeValue"></el-option>
                </el-select> -->
                <el-button type="primary" icon="search" @click="getInfo">搜索</el-button>
                <el-button type="primary" @click="flushAll">刷新</el-button>
              </div>
              <el-row style="margin-top:20px">
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?3:0">
                      <treeComponent style="margin-top:-52px" @GetNodeValue="GetNodeValue"></treeComponent>
                  </el-col>
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?21:24">
                      <el-table :data="list" border>
                          <el-table-column v-for="(v,k,i) in props" :key="v.id" :label="labels[i]" align="center">
                              <template scope="scope">
                                  <span v-if="k==='sex'">
                                       {{scope.row[k]==1?'男':'女'}}
                                  </span>
                                   <span v-else-if="k=='eventKind'">
                                    {{scope.row[k]==1?'一般事件':'重大事件'}}
                                  </span>
                                  <span v-else>
                                      {{scope.row[k]}}
                                  </span>
                              </template>
                          </el-table-column>
                          <el-table-column label="操作" width="200" align="center">
                              <template scope="scope">
                                  <el-button size="small" v-if="scope.row.eventStatusTypeValue=='05'||scope.row.eventStatusTypeValue=='08'" type="success" @click="eventDeal(scope.row.eventID)">事件处理</el-button>
                                  <el-button type="text" @click="ckDetail(scope.row.eventID)">查看详情</el-button>
                              </template>
                          </el-table-column>
                      </el-table>
                       <el-pagination style="margin-top:10px;float:right" layout="prev, pager, next" :total="totalInfo"  @current-change="handleCurrentChange">
                      </el-pagination>
                  </el-col>
              </el-row>
          </el-col>
      </el-row>
      <el-dialog title="事件处理" :visible.sync="visible" :before-close="handleClose">
        <el-form :model="form" label-width="180px">
          <el-form-item label="事件处理人ID" style="width:600px">
            <el-input disabled v-model="form.dealingUserID" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="处理时间">
            <el-date-picker  v-model="form.dealingTime" placeholder=""></el-date-picker>
          </el-form-item>
          <el-form-item label="处理情况">
            <el-input style="width:500px" v-model="form.dealingInf" type="textarea" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="备注" style="width:600px">
            <el-input v-model="form.remark" placeholder=""></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="deal()">确认处理</el-button>
          </el-form-item>
          <el-form-item v-if="form.eventDealingID!==''&&form.eventDealingID!==null">
              <h1>图片、视频信息</h1>
            </el-form-item>
            <el-form-item v-if="form.eventDealingID!==''&&form.eventDealingID!==null">
               <el-upload
              class="upload-demo"
              :action="getDomain()+'/msmis/api/netGrid/addNetGridEventDealingPictures?ID='+form.eventDealingID"
              :headers="header"
              :file-list="fileList"
              list-type="picture">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">可上传jpg/jpeg/png文件</div>
            </el-upload>
            </el-form-item>
            <el-form-item v-if="form.eventDealingID!==''&&form.eventDealingID!==null">
              <h4>视频上传</h4>
              <el-upload
                class="upload-demo"
                drag
                :action="getDomain()+'/msmis/api/netGrid/addNetGridEventDealingVideo?ID='+form.eventDealingID"
                :headers="header"
                multiple>
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将视频拖到此处，或<em>点击上传</em></div>
              </el-upload>
            </el-form-item>
            <el-form-item align="center">
              <el-button type="primary" @click="visible = false"></el-button>
            </el-form-item>
        </el-form>
      </el-dialog>

      <el-dialog  top="5%" title="查看详情" :visible.sync="visible2">
      <info :id="id"></info>
    </el-dialog>
  </div>
</template>

<script>
import treeComponent from "../../components/common/treeComponent";
import * as api from "../../api/netGridManage";
import * as api2 from "../../api/securityManage";
import { getToken } from '../../utils/auth';
import * as socket from "@/api";
import info from "./netEventInfo";
export default {
  components: {
    treeComponent: treeComponent,
    info:info
  },
  data() {
    return {
      header:{
        token:getToken()
      },
      currentPage:1,
      visible: false,
      filters: {
        id: 4,
        name: null,
        kind: null,
        netGridID: null,
        status:null,
        page: 1,
        pageSize: 10
      },
      EventStatus:[],
      fileList: [],
      currentID: "",
      form: {
        eventDealingID: "",
        eventID: "",
        dealingUserID: 4, //        bigint comment '处理任务的人的用户ID',
        dealingTime: "", //          datetime,
        dealingInf: "", //           varchar(1000) comment '处理情况文字描述',
        remark: "" //               varchar(500),
      },
      list: [
        {
          eventID: "", //            bigint not null auto_increment,
          eventName: "", //           '事件名称',
          eventKind: "", //           '事件性质，如1=一般事件；2=重大事件；等',
          eventTypeValue: "", //      '事件类型，如杀人、放火、抢劫等',
          eventContent: "", //         ,
          eventStartDateTime: "", //   datetime,
          // eventEndDateTime:'',//     datetime,
          eventHappenLongitude: "", // '地理经度信息',
          eventHappenLatitude: "", //  comment '地理纬度信息',
          eventStatusTypeValue: "", //   '当前事件处理的最新状态',
          currentRemarks: "", //        ,
          currentResponsiblePersonCertID: "", // '当前经办人员身份证号',
          currentResponsiblePersonName: "", //'当前经办人员姓名',
          currentResponsiblePersonContact: "", //'经办人员联系方式',
          netGridID: "" // ,
        }
      ],
      totalInfo: 0,
      props: {
        eventName: "",
        eventKind: "", //               '事件性质，如1=一般事件；2=重大事件；等',
        eventTypeName: "", //          '事件类型，如杀人、放火、抢劫等',
        eventStatusTypeName: "", //     '当前事件处理的最新状态',
        eventStartDateTime:'',
        netGridName: "" //所属网格
      },
      labels: [
        "事件名称",
        "事件性质",
        "事件类型",
        "事件处理状态",
        "发生日期",
        "所属网格"
      ],
      visible2:false,
      id:'01'
    };
  },
  methods: {
    getDomain(){
      return 'http://' + window.location.host;
    },
    handleClose(done) {
      this.form.eventDealingID = "";
      done();
    },
    deal() {
      this.form.eventID = this.currentID;
      this.$confirm("是上传此事件的处理记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          api.addNetGridEventDealingBasic(this.form).then(res => {
            if (res.code == 200) {
              this.form.eventDealingID = res.data;
              this.$message({
                type: "success",
                message: "事件处理信息上传成功！"
              });
              socket.send({username:4,message:'有新的问题事件需要审核!'});
              api.updateNetGridEventStatus("06", this.form.eventID).then(res => {
                if (res.code == 200) {
                  this.$message({
                    type: "success",
                    message: "等待审核！"
                  });
                  this.getInfo();
                }
              });
            } else {
              this.$message({
                type: "error",
                message: "事件处理信息上传失败！"
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消上传事件处理信息！"
          });
        });
    },
    eventDeal(id) {
      this.currentID = id;
      this.visible = true;
    },
    flushAll() {
     this.filters.name = this.filters.kind = this.filters.netGridID = this.filters.status = null;
      this.getInfo();
    },
    handleCurrentChange(val) {
      this.filters.page = val;
      this.getInfo();
    },
    ckDetail(id) {
      this.id = id;
      this.visible2 = true;
    },
    addNewRecord() {
      this.$router.push("add");
    },
    GetNodeValue(val) {
      this.filters.netGridID = val;
      this.getInfo();
    },
    editEvent(id) {
      this.$router.push({ path: "editDeal", query: { id: id } });
    },
    getInfo() {
      api.getNetGridEventHandlerQuery(this.filters).then(res => {
        this.list = res.data.vos;
        this.totalInfo = res.data.page.totalCount;
      });
      this.filters.name = this.filters.kind = this.filters.netGridID = this.filters.status = null;
    }
  },
  mounted() {
    this.form.dealingUserID = this.$store.getters.user.userID
    this.filters.id = this.$store.getters.user.userID
    if(this.$store.getters.user.userRole!='超级管理员')
      this.filters.netGridID = this.$store.getters.user.netGridID
    this.getInfo();
    api2.getSSEventCode().then(res=>{
        this.EventStatus = res.data.EventStatusType
    })
  }
};
</script>


<style scoped>

</style>
